<template>
  <transition name="fade">
    <div id="PopupsBox" v-if="popupsShow" @click="popupsShow = false">
      <div class="PopupsBox" :class="{ max: type == 'max' }" @click.stop>
        <div class="title" v-if="title">{{ title }}</div>
        <div class="content" v-if="message">{{ message }}</div>
        <div class="button" @click="close">{{ btn_text || "确定" }}</div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {
      popupsShow: false,
      type: null,
      title: null,
      message: null,
      onEnter: null,
      btn_text: null,
    };
  },
  methods: {
    noFun(onEnter) {
      this.show({
        title: "功能开发中",
        message: "配将助手将提供发布配将需求让大佬帮忙配将的功能，敬请期待。",
        onEnter: onEnter,
      });
    },
    noApp() {
      this.show({
        type: "max",
        title: "此功能仅可在GankeAPP中使用",
        onEnter: window.injectedAll.download,
      });
    },
    show({ type, title, message, onEnter, btn_text }) {
      this.popupsShow = true;
      this.type = type;
      this.title = title;
      this.btn_text = btn_text;
      this.message = message;
      this.onEnter = onEnter;
    },
    close() {
      this.popupsShow = false;
      this.onEnter && this.onEnter();
      this.type = null;
      this.title = null;
      this.btn_text = null;
      this.message = null;
      this.onEnter = null;
    },
  },
};
</script>

<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active, 2.1.8 版本以下 */ {
  opacity: 0;
}
#PopupsBox {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  .PopupsBox {
    width: 2.4rem;
    background: #ffffff;
    border-radius: 8px;
    padding: 0 0.15rem;
    &.max {
      .title {
        padding: 0.36rem 0 0.17rem 0;
      }
    }
    .title {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      line-height: 20px;
      text-align: center;
      padding: 0.16rem 0 0.06rem 0;
    }
    .content {
      font-size: 12px;
      font-weight: 400;
      color: #8c8c8c;
      line-height: 17px;
    }
    .button {
      height: 0.32rem;
      background: #ff8a69;
      border-radius: 0.18rem;
      font-size: 0.14rem;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #ffffff;
      margin: 0.13rem 0 0.19rem 0;
    }
  }
}
</style>
